﻿Public Class frmWebsites
    'Dim Data As New List(Of Website)
    Dim File As New FS.File_Folder("C:\Aaron Extension\Websites.XML")

    Private ReadOnly Property DataSource As List(Of Website)
        Get
            OlvColumn1.IsVisible = False
            Return (DataListView1.DataSource)
        End Get
    End Property


#Region "       Static     >>>"

    Private Sub frmWebsites_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not File.Parent.Exists Then File.Parent.Create()
        If Not File.Exists Then
            File.Create()
            DataListView1.DataSource = New List(Of Website)
        Else
            DataListView1.DataSource = Mod_Actions.Mod_XML.Read_XML_Data(Of Website)(File.URL)
        End If
        Me.DataListView1.BuildGroups(OlvColumn1, Windows.Forms.SortOrder.Ascending)
        OlvColumn1.IsVisible = False
    End Sub


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        DataSource.Add(New Website With {.Name = "Nothing"})
        DataListView1.DataSource = DataListView1.DataSource
    End Sub

    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
        If Me.DataListView1.SelectedIndex > -1 Then
            DataSource.RemoveAt(Me.DataListView1.SelectedIndex)
            'Me.ObjectListView1.Objects = Data
        Else
            MsgBox("Please Select A Row")
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Mod_Actions.Mod_XML.Write_XML_Data(DataSource, File.URL, "")
    End Sub
#End Region


    Private Sub ObjectListView1_CellClick(ByVal sender As System.Object, ByVal e As BIS.CellClickEventArgs) Handles DataListView1.CellClick
        PropertyGrid1.SelectedObject = e.Model
    End Sub



    Private Sub ObjectListView1_HyperlinkClicked(ByVal sender As System.Object, ByVal e As BIS.HyperlinkClickedEventArgs) Handles DataListView1.HyperlinkClicked
        If Not e.Url.ToLower.Contains("www.") And Not e.Url.ToLower.Contains("http") Then e.Handled = True
    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        DataListView1.DataSource = DataSource
        OlvColumn1.IsVisible = False
    End Sub



    Private Sub PropertyGrid1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PropertyGrid1.Leave
        If DataListView1.SelectedIndex = -1 Then Exit Sub
        DataSource(DataListView1.SelectedIndex) = PropertyGrid1.SelectedObject
        DataListView1.DataSource = DataSource
        OlvColumn1.IsVisible = False
    End Sub
End Class